<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');



//factory database to create object plexiable
class model_word_server extends model_word{
    
    function get_all(){
        
        $query = $this->db->query('YOUR QUERY HERE');

    }
    
    function get($int){
        $query = $this->db->get_where($this->config->item('database_suffix').'words', array('topic_id' => $int,'is_deleted'=>false));
        $result= $query->result();
        return $result;
        $max=8;
        if($max>count($result))
            $max=count($result)-1;
        $rand=array_rand($result,$max);
        $lst=array();
        //var_dump($max);
        for($i=0;$i<$max;$i++){
            array_push($lst,$result[$rand[$i]]);
        }
        //var_dump($lst);
        return $lst;
    }
    
    function get_for_game($int){
        $query = $this->db->get_where($this->config->item('database_suffix').'words', array('topic_id' => $int,'is_deleted'=>false));
        $result= $query->result();
        //return $result;
        $max=8;
        if($max>count($result))
            $max=count($result)-1;
        $rand=array_rand($result,$max);
        $lst=array();
        //var_dump($max);
        for($i=0;$i<$max;$i++){
            array_push($lst,$result[$rand[$i]]);
        }
        //var_dump($lst);
        return $lst;
    }
    
    
    
    function insert($word){
        $this->db->insert($this->config->item('database_suffix').'words', $word);
        $this->db->select('max(id) as id');
        $this->db->from($this->config->item('database_suffix').'words');
        $query=$this->db->get();
        $object=$query->result();
        return $object[0]->id;
    }
    
    function update($int,$word){
        $this->db->where('id', $int);
        $query=$this->db->update($this->config->item('database_suffix').'words', $word);
        //var_dump($query);
        return $query;
    }
    
    function delete($int){
        $this->db->where('id', $int);
        $query=$this->db->update($this->config->item('database_suffix').'words', array("is_deleted"=>true));
        //var_dump($query);
        return $query;
    }
}